﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * ZIP Version Information Base Class
 * 		Provides a base definition for version information containers in a PKZIP-
 * formatted file.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;

namespace Adaptive.Foundation.IO.Zip
{
/// <summary>
/// Provides a base definition for version information containers in a PKZIP-
/// formatted file.
/// </summary>
/// <remarks>
/// Version data is always stored as 2 byte short integer values.
/// </remarks>
    public abstract class ZipVersionBase : AiObjectBase
    {
        /*--------------------------------------------------------------------------------
         * Private Member Declarations
         *------------------------------------------------------------------------------*/
        #region Private Member Declarations
        /// <summary>
        /// The high-order byte value.
        /// </summary>
        private byte _highByte;

        /// <summary>
        /// The low-order byte value.
        /// </summary>
        private byte _lowByte;
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the <see cref="ZipVersionBase" /> class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        protected ZipVersionBase()
            : base()
        {
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ZipVersionBase" /> class.
        /// </summary>
        /// <param name="highOrderByte">The high order byte value.</param>
        /// <param name="lowOrderByte">The low order byte value.</param>
        protected ZipVersionBase(byte highOrderByte, byte lowOrderByte)
            : base()
        {
            _highByte = highOrderByte;
            _lowByte = lowOrderByte;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ZipVersionBase" /> class.
        /// </summary>
        /// <param name="value">The short integer value containing the versioning data.</param>
        protected ZipVersionBase(short value)
            : base()
        {
            _highByte = (byte)(value >> 8);
            _lowByte = (byte)((value << 8) >> 8);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Properties
         *------------------------------------------------------------------------------*/
        #region Protected Properties
        /// <summary>
        /// Gets or sets the high-order byte value.
        /// </summary>
        /// <value>The high-order byte value.</value>
        protected byte HighByte
        {
            get
            {
                return _highByte;
            }
            set
            {
                _highByte = value;
            }
        }
        /// <summary>
        /// Gets or sets the low-order byte value.
        /// </summary>
        /// <value>The low-order byte value.</value>
        protected byte LowByte
        {
            get
            {
                return _lowByte;
            }
            set
            {
                _lowByte = value;
            }
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Properties
         *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>A short integer value containing the versioning data.</value>
        public short Value
        {
            get
            {
                return (short)(Convert.ToInt16(_highByte << 8) + Convert.ToInt16(_lowByte));
            }
            set
            {

                _highByte = (byte)(value >> 8);
                _lowByte = (byte)((value << 8) >> 8);
            }
        }
        #endregion
    }

}